{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a1c287e8",
   "metadata": {},
   "source": [
    "Task 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f2fb1b9c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "\n",
    "def Task1():\n",
    "    c=csv.reader(open(os.path.dirname(__file__)+'\\gaze.csv','r'))\n",
    "    next(c)\n",
    "    res=0\n",
    "    for row in c:\n",
    "        if float(row[2])>0.9:\n",
    "            res+=1\n",
    "    return res #result=87442"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd5418e8",
   "metadata": {},
   "source": [
    "Task 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9d65595f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "\n",
    "def getMeanStd(li):\n",
    "    tCount=len(li)\n",
    "    tSum=sum(li)\n",
    "    tMean=tSum/tCount\n",
    "    tStd=0\n",
    "    for i in li:\n",
    "        tStd+=(i-tMean)**2\n",
    "    tStd=(tStd/tCount)**0.5\n",
    "    return (tMean,tStd)\n",
    "\n",
    "def Task2():\n",
    "    c=csv.reader(open(os.path.dirname(__file__)+'\\gaze.csv','r'))\n",
    "    next(c)\n",
    "    colx=[]\n",
    "    coly=[]\n",
    "    for row in c:\n",
    "        colx.append(float(row[3]))\n",
    "        coly.append(float(row[4]))\n",
    "    meanx,stdx=getMeanStd(colx)\n",
    "    meany,stdy=getMeanStd(coly)\n",
    "    h1=meanx-3*stdx\n",
    "    h2=meanx+3*stdx\n",
    "    h3=meany-3*stdy\n",
    "    h4=meany+3*stdy\n",
    "    res=0\n",
    "    c=csv.reader(open(os.path.dirname(__file__)+'\\gaze.csv','r'))\n",
    "    next(c)\n",
    "    for row in c:\n",
    "        if h1<=float(row[3])<=h2 and h3<=float(row[4])<=h4:\n",
    "            res+=1\n",
    "    return res #result=120036"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91e6b0ea",
   "metadata": {},
   "source": [
    "Task3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ffce9ed9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "import datetime\n",
    "\n",
    "def Task3():\n",
    "    c=csv.reader(open(os.path.dirname(__file__)+'\\gaze.csv','r'))\n",
    "    res=[]\n",
    "    for i,row in enumerate(c):\n",
    "        if i>=1:\n",
    "            tick=datetime.datetime.fromtimestamp(float(row[0]))\n",
    "            temp=tick.strftime(\"%Y-%m-%d %H:%M:%S.%f\")\n",
    "            res.append(temp)\n",
    "            if i<=20:\n",
    "                print(temp)\n",
    "    return res\n",
    "\n",
    "'''\n",
    "1970-01-02 08:29:10.776780\n",
    "1970-01-02 08:29:10.776787\n",
    "1970-01-02 08:29:10.779709\n",
    "1970-01-02 08:29:10.779759\n",
    "1970-01-02 08:29:10.787485\n",
    "1970-01-02 08:29:10.787580\n",
    "1970-01-02 08:29:10.789480\n",
    "1970-01-02 08:29:10.793583\n",
    "1970-01-02 08:29:10.795683\n",
    "1970-01-02 08:29:10.798406\n",
    "1970-01-02 08:29:10.801140\n",
    "1970-01-02 08:29:10.802973\n",
    "1970-01-02 08:29:10.804631\n",
    "1970-01-02 08:29:10.807269\n",
    "1970-01-02 08:29:10.809749\n",
    "1970-01-02 08:29:10.812873\n",
    "1970-01-02 08:29:10.814136\n",
    "1970-01-02 08:29:10.815998\n",
    "1970-01-02 08:29:10.818051\n",
    "1970-01-02 08:29:10.821819\n",
    "'''"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6bd6977e",
   "metadata": {},
   "source": [
    "Task4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48eeea22",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "\n",
    "def Task4():\n",
    "    c=csv.reader(open(os.path.dirname(__file__)+'\\gaze.csv','r'))\n",
    "    count=0\n",
    "    st=1e19\n",
    "    ed=-1e19\n",
    "    for i,row in enumerate(c):\n",
    "        if i>=1:\n",
    "            count+=1\n",
    "            st=min(st,float(row[0]))\n",
    "            ed=max(ed,float(row[0]))\n",
    "    return count/(ed-st) #result=427.62610766083765(Hz)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb956f96",
   "metadata": {},
   "source": [
    "Task5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8c95513",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "\n",
    "def Task5():\n",
    "    c=csv.reader(open(os.path.dirname(__file__)+'\\gaze.csv','r'))\n",
    "    next(c)\n",
    "    mem=-1\n",
    "    res=[]\n",
    "    for row in c:\n",
    "        if float(row[0])-mem>=0.01:\n",
    "            res.append(row)\n",
    "            mem=float(row[0])\n",
    "    for i in range(20):\n",
    "        print(res[i])\n",
    "    return res\n",
    "\n",
    "'''\n",
    "['88150.77678', '0', '0.8280059462620806', '0.5314327126985153', '0.39750946211500204', '88150.77678-0', '28.369752901573236', '52.033134560158175', '705.1211159195539', '20.0', '15.0', '-20.0', '0.01152676874215287', '0.051001789765111646', '0.9986320398640939', '', '', '', '', '', '']\n",
    "['88150.787485', '1', '0.5025948800258426', '0.3401089118572799', '0.14298949506249015', '88150.787485-1', '-139.4048601388959', '175.088321362755', '681.1514528333081', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.13698933743054134', \n",
    "'0.2204754503935745', '0.9657248558487515', '', '', '', '', '', '']\n",
    "['88150.79840649999', '1', '0.7084760742125342', '0.4941157090777496', '0.4071094106264913', '88150.79569-0 88150.801123-1', '2.1796287066650546', '-19.354529932692056', '-289.3865972267117', '20.0', '15.0', '-20.0', '0.06514516047431963', '0.027374145920454677', '0.9975002577452808', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1525226416003532', '0.22265933259715345', '0.9628913050841411']\n",
    "['88150.8097485', '1', '0.8563407607235008', '0.4948883596911874', '0.4022157050625298', '88150.809749-0 88150.809748-1', '1.8876775693366525', '-20.312302916953133', '-288.5078002264259', '20.0', '15.0', '-20.0', '0.066337739085217', '0.02383990799003523', '0.9975123874719999', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.15178084031019365', '0.23367889243106407', '0.9603940606578754']\n",
    "['88150.821819', '2', '0.861112802026488', '0.49345299232127626', '0.3998385355256633', '88150.823534-0 88150.820104-1', '2.4518232083297207', '-21.099370287407083', '-292.5744058209181', '20.0', '15.0', '-20.0', '0.06331981940889361', '0.025199443737810433', '0.9976750916532551', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1515273956574198', '0.23414301276977342', '0.9603210389949675']\n",
    "['88150.83369', '2', '0.7924554336009598', '0.4931383309317702', '0.39879834271819814', '88150.831679-0 88150.83570099999-1', '2.570654007363393', '-21.326717207100174', '-292.6873073129334', '20.0', '15.0', '-20.0', '0.06287006068157094', '0.02741066830429456', '0.9976452329024624', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.15188909468215658', '0.23346737957802458', '0.9604283864971951']\n",
    "['88150.84749249999', '3', '0.8146346350814423', '0.49268465705635095', '0.3989208383436903', '88150.85153599999-0 88150.84344899999-1', '2.776177148200823', '-21.577277273604157', '-296.4848556983736', '20.0', '15.0', '-20.0', '0.061283019104364955', '0.02566851258753678', '0.9977903181686012', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1505621238051983', '0.23344803725625876', '0.960642004482663']\n",
    "['88150.8580525', '3', '0.8028764861728308', '0.49310060776833786', '0.3978841406342749', '88150.85654-0 88150.85956499999-1', '2.6335231752731048', '-21.92512270062688', '-298.20597403352224', '20.0', '15.0', '-20.0', '0.06140321642039546', '0.025916912799037132', '0.9977765073623442', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14915185946327889', '0.2340532138000838', '0.9607147422250263']\n",
    "['88150.86962', '3', '0.922197307158175', '0.49263493312230366', '0.3988137517485483', '88150.867514-0 88150.871726-1', '2.8137737507053764', '-21.744854170303462', '-298.47125345128484', '20.0', '15.0', '-20.0', '0.06071702183202721', '0.025219893820897885', '0.9978363594375146', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14964541784424926', '0.23325783877395026', '0.9608314261975022']\n",
    "['88150.881738', '4', '0.94500047108518', '0.49231789502851864', '0.3989757058831216', '88150.879586-0 88150.88389-1', '2.9448756619455043', '-21.783872023277713', '-299.48615899364256', '20.0', '15.0', '-20.0', '0.06004036186469085', '0.024936294324659092', '0.9978844302686117', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14956825585505618', '0.2328956455844725', '0.9609312957273628']\n",
    "['88150.89360899999', '4', '0.8550647363113325', '0.49196301857445757', '0.3980274149338666', '88150.89551599999-0 88150.891702-1', '3.1042410838204244', '-22.154830596727386', '-301.7536334011173', '20.0', '15.0', '-20.0', '0.05899829367017455', '0.024598649249555092', '0.9979549628110009', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14891582435890977', '0.23373323204977325', '0.9608292530367055']\n",
    "['88150.90549549999', '4', '0.860093311910097', '0.49155932443364775', '0.3981537095713097', '88150.90741599999-0 88150.90357499999-1', '3.2627763654987465', '-22.145110012300265', '-301.9952627615938', '20.0', '15.0', '-20.0', '0.05839478901870607', '0.02400047627187978', '0.998005022910298', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14932225425095516', '0.23403121968543314', '0.9606936309760579']\n",
    "['88150.917009', '5', '0.8383589621749243', '0.4916988785237518', '0.39698290407830483', '88150.91700999999-0 88150.91700799999-1', '3.2059927353378015', '-22.379871794808', '-301.72812572966956', '20.0', '15.0', '-20.0', '0.05864262281509698', '0.02531090342311198', '0.9979581158331612', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14925633872709826', '0.2345754008162153', '0.9605711460801297']\n",
    "['88150.9275245', '5', '0.853040894539125', '0.4914520921772419', '0.39748468234276335', '88150.927522-0 88150.92752699999-1', '3.323771199109265', '-22.422424924445156', '-303.7814987183897', '20.0', '15.0', '-20.0', '0.057815106883074265', '0.023935124425489368', '0.9980403414866735', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14860165931375657', '0.2343942415664973', '0.9607168606669007']\n",
    "['88150.93855949999', '5', '0.9987443957942154', '0.49116162292077215', '0.3963212280529863', '88150.93622799999-0 88150.94089099999-1', '3.444670660175696', '-22.729377983279125', '-304.48451442370134', '20.0', '15.0', '-20.0', '0.05725573600184664', '0.02556757341574248', '0.9980321036342059', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1486475062957136', '0.23424002017754897', '0.9607473818956195']\n",
    "['88150.9515035', '6', '0.8036163788282745', '0.4914462011441675', '0.3964083710376737', '88150.947523-0 88150.95548399999-1', '3.321166938820271', '-22.6244933057039', '-303.33442657283535', '20.0', '15.0', '-20.0', '0.05791441579586018', '0.025849307221017352', '0.9979868404739706', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1488208667257802', '0.23427704473976166', '0.9607115154587205']\n",
    "['88150.963509', '6', '0.8391189191753998', '0.49090473547679114', '0.3976818984011624', '88150.963521-0 88150.96349699999-1', '3.53688257800637', '-22.381042288032962', '-303.80529417440346', '20.0', '15.0', '-20.0', '0.057074997183387884', '0.023794625042328963', '0.9980862991323006', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14930820196503153', '0.23422450221077076', '0.9606487096697138']\n",
    "['88150.9735785', '6', '0.8323449609247241', '0.4909156820562581', '0.39684439718593', '88150.97157499999-0 88150.975582-1', '3.5523058741625295', '-22.68994150748757', '-305.4977799518024', '20.0', '15.0', '-20.0', '0.05669159854217565', '0.025577509350689427', '0.9980640528894672', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.1485120491491692', '0.2330814485583527', '0.9610500557179396']\n",
    "['88150.98563049998', '7', '0.7901185312519243', '0.49088686650596625', '0.3971135069972528', '88150.98779799999-0 88150.983463-1', '3.559689066758999', '-22.606078088353634', '-305.16474769366056', '20.0', '15.0', '-20.0', '0.05671956251705809', '0.02323256372590157', '0.9981198020331008', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14867360241512462', '0.23509174399344632', '0.9605352840218986']\n",
    "['88150.9975725', '7', '0.8832206748586864', '0.49127045849255635', '0.39747908216004', '88150.995489-0 88150.999656-1', '3.419142715878353', '-22.587117278932016', '-305.99605311484345', '20.0', '15.0', '-20.0', '0.05704096718857227', '0.022851307064208425', '0.9981102874069832', '-39.93492801030824', '14.997919452545707', '-20.075282531198983', '-0.14779191170952047', '0.23462382871415896', '0.9607857252440601']\n",
    "'''"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
